package com.power.web;

import com.github.pagehelper.PageInfo;
import com.power.model.TActivityRemark;
import com.power.query.ActivityRemarkQuery;
import com.power.result.R;
import com.power.service.ActivityRemarkService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class ActivityRemarkController {
    @Resource
    private ActivityRemarkService activityRemarkService;

    @PostMapping("/api/activity/remark")
    public R addActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery, @RequestHeader("token") String token) {
        activityRemarkQuery.setToken(token);
        int saveCount = activityRemarkService.addActivityRemark(activityRemarkQuery);
        return saveCount >= 1 ? R.OK() : R.FAIL();
    }

    @GetMapping("/api/activity/remark")
    public R getActivityRemarkList(@RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage,
                                   @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                   @RequestParam(value = "activityId") Integer activityId) {
        ActivityRemarkQuery activityRemarkQuery = ActivityRemarkQuery.builder().activityId(activityId).build();
        PageInfo<TActivityRemark> userByPage = activityRemarkService.selectActivityRemarkByPage(currentPage, pageSize, activityRemarkQuery);
        return R.OK(userByPage);
    }

    @GetMapping(value = "/api/activity/remark/{id}")
    public R getActivityRemarkDetail(@PathVariable(value = "id") Integer id) {
        TActivityRemark tActivityRemark = activityRemarkService.selectActivityRemarkDetailById(id);
        return R.OK(tActivityRemark);
    }

    @PutMapping("/api/activity/remark")
    public R updateActivityDemark(@RequestBody ActivityRemarkQuery activityRemarkQuery, @RequestHeader("token") String token) {
        activityRemarkQuery.setToken(token);
        int updateCount = activityRemarkService.updateActivityDemark(activityRemarkQuery);
        return updateCount >= 1 ? R.OK() : R.FAIL();
    }

    @DeleteMapping(value = "/api/activity/remark/{id}")
    public R deleteActivityRemark(@PathVariable(value = "id") Integer id) {
        int deleteCount = activityRemarkService.deleteActivityRemarkById(id);
        return deleteCount >= 1 ? R.OK() : R.FAIL();
    }
}
